package com.gua.jbs.daoImpl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.gua.jbs.dao.IInvoiceDao;
import com.gua.jbs.utility.ApplicationException;
import com.gua.jbs.utility.DBConstant;
import com.gua.jbs.utility.ExceptionMessage;
import com.gua.jbs.utility.QueryConstant;

public class InvoiceDao extends BaseDao implements IInvoiceDao{

	@Override
	public List<String> getGeneratedInvoiceNo() throws ApplicationException {
		// TODO Auto-generated method stub
		List lParamList = new ArrayList();
		lParamList.add(0, DBConstant.CODE_GROUP_INVOICE);
		
		List<String> list_invoice=new ArrayList<String>();
				
		String query = getQuery(QueryConstant.GET_INVOICE_NO,lParamList);
		try {
			ResultSet rs = getResults(query);
			while (rs.next()) {
				
				list_invoice.add(rs.getString("CODE_ID"));
				list_invoice.add(rs.getString("CODE_NAME"));
				list_invoice.add(rs.getString("CODE_VALUE"));
			} 
		}
		 catch (SQLException sqe) {
				throw new ApplicationException(ExceptionMessage.INVOICE_NOT_UNABLE);
		}
		return list_invoice;
	}

	/**
	 * Method to update the invoice generator count
	 * @param invoiceValue
	 * @return
	 * @throws ApplicationException
	 */
	public boolean updateInvoiceNo(String invoiceValue)
			throws ApplicationException {
		// TODO Auto-generated method stub
		boolean isUpdated = false;
		List lParamList = new ArrayList();
		lParamList.add(0,invoiceValue);
		lParamList.add(1, DBConstant.CODE_NAME_INVOICE);
				
		String query = getQuery(QueryConstant.UPDATE_INVOICE_NO,lParamList);
		int resultCount = 0;
		try {
			resultCount = update(query);
			if (resultCount != 0) {
				isUpdated = true;
			} else
				isUpdated = false;
		} catch (SQLException sqe) {
			throw new ApplicationException(ExceptionMessage.INVOICE_NOT_UPDATED);
		}
		return isUpdated;
	}
}
